package com.example.x50.untils;

import android.util.Log;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import cn.hutool.core.io.file.FileReader;

public class FileIO {
    private static final String LOG_TAG = "文件";
    public static File getAlbumStorageDir(String albumName) {
        File file = new File(albumName);
        if (file.exists()){
            file.delete();
        }
        try {
            //创建文件
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (!file.exists()) {
            Log.e(LOG_TAG, "Directory not created");
        }
        return file;
    }

    public static void write(String string) throws IOException {
        File file = new File("data/data/com.example.zuizhongfabu/conf.json");
        if (file.exists()){
            file.delete();
        }
        try {
            //创建文件
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileWriter writer = new FileWriter("data/data/com.example.zuizhongfabu/conf.json");
        writer.write(string);
        writer.close();
        FileReader fileReader = new FileReader("data/data/com.example.zuizhongfabu/conf.json");
        String result = fileReader.readString();
        Log.e(LOG_TAG,result);
    }
    public static String read() throws IOException {
        FileReader fileReader = new FileReader("data/data/com.example.zuizhongfabu/conf.json");
        String result = fileReader.readString();
        return result;
    }
}